<html>
<head><meta charset="utf-8"><title>problem with async trait workaround · wg-async-foundations · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/index.html">wg-async-foundations</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/problem.20with.20async.20trait.20workaround.html">problem with async trait workaround</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="233674681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/problem%20with%20async%20trait%20workaround/near/233674681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zeeshan Ali <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/problem.20with.20async.20trait.20workaround.html#233674681">(Apr 08 2021 at 15:29)</a>:</h4>
<p><span class="user-mention" data-user-id="224872">@rylev</span> hey, remind me again what issues Allan is expected to have on the impl. side of his trait returning a generic future? </p>
<blockquote>
<p>Alan seems to have something working, but when he goes to update the examples of how to implement this trait in his crate's documentation, he realizes it doesn't work.</p>
</blockquote>
<p>The issue I see is that implementers either have to <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=5e04c9a7b4c03b268569adb62e2c79bb">box/dynamic dispatch</a> as well or implement Future manually (which isn't something Allan would enjoy). Is that what we meant?</p>



<a name="233675809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/problem%20with%20async%20trait%20workaround/near/233675809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rylev <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/problem.20with.20async.20trait.20workaround.html#233675809">(Apr 08 2021 at 15:35)</a>:</h4>
<p>If we look at this code <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=b2f323f6869b198f9d51b0bf636d3006">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=b2f323f6869b198f9d51b0bf636d3006</a> - There's only two choices for the associated type: <code>Box&lt;dyn Future&gt;</code> or some custom type that implements <code>Future</code>. A custom future type would work... We could have Alan do that, but it's messy code. If however, Alan wants to use async/await without boxing the resultant future, that's simply not possible.</p>



<a name="233679298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/problem%20with%20async%20trait%20workaround/near/233679298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zeeshan Ali <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/problem.20with.20async.20trait.20workaround.html#233679298">(Apr 08 2021 at 15:56)</a>:</h4>
<p>right. It has to be <code>Pin&lt;Box&lt;dyn Future&gt;&gt;</code> btw. Allan will likely struggle with that <strong>a bit</strong> too.</p>



<a name="233679556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/problem%20with%20async%20trait%20workaround/near/233679556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zeeshan Ali <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/problem.20with.20async.20trait.20workaround.html#233679556">(Apr 08 2021 at 15:58)</a>:</h4>
<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=b234b1dc2c913668f1d7a75515315d47">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=b234b1dc2c913668f1d7a75515315d47</a></p>



<a name="233689769"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/problem%20with%20async%20trait%20workaround/near/233689769" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Andrew Chin (eminence) <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/problem.20with.20async.20trait.20workaround.html#233689769">(Apr 08 2021 at 17:02)</a>:</h4>
<p>i also wonder if Alan would try <code>type Fut = impl std::future::Future;</code></p>



<a name="233721045"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/problem%20with%20async%20trait%20workaround/near/233721045" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zeeshan Ali <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/problem.20with.20async.20trait.20workaround.html#233721045">(Apr 08 2021 at 20:17)</a>:</h4>
<p><span class="user-mention" data-user-id="224872">@rylev</span> actually, custom <code>Future</code> impl would work fine with async/await: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=ec5023946b838dd2412c2d540a1dd507">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=ec5023946b838dd2412c2d540a1dd507</a> . They might need to pin the future but they can do that using <code>pin_utils::pin_mut</code> macro.</p>



<a name="233727490"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/problem%20with%20async%20trait%20workaround/near/233727490" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rylev <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/problem.20with.20async.20trait.20workaround.html#233727490">(Apr 08 2021 at 21:01)</a>:</h4>
<p>I meant using async/await as the body of the trait function. That’s not possible</p>



<a name="233731105"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/problem%20with%20async%20trait%20workaround/near/233731105" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zeeshan Ali <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/problem.20with.20async.20trait.20workaround.html#233731105">(Apr 08 2021 at 21:16)</a>:</h4>
<p>gotcha. PR is up: <a href="https://github.com/rust-lang/wg-async-foundations/pull/134">https://github.com/rust-lang/wg-async-foundations/pull/134</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>